home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!usenet
- From: clamage@Eng.sun.com (Steve Clamage)
- Newsgroups: comp.std.c++
- Subject: Re: Constructors and conversion operator
- Date: 19 Mar 1996 16:40:40 GMT
- Organization: Sun Microsystems Inc.
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <4imnnl$j29@engnews1.Eng.Sun.COM>
- References: <314E1D5D.76E5@cs.tu-berlin.de>
- Reply-To: clamage@Eng.sun.com
- NNTP-Posting-Host: taumet.eng.sun.com
- X-Nntp-Posting-Host: taumet.eng.sun.com
- Content-Length: 1353
- X-Lines: 30
-
- In article 76E5@cs.tu-berlin.de, Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
- >
- >The DWP defines:
- >
- >A constructor declared without the function-specifier explicit that
- > can be called with a single parameter specifies a conversion from the
- > type of its first parameter to the type of its class. [class.conv.ctor]
- >
- >Now, to me this means that a copy constructor is a converting constructor
- >since it takes a single parameter which is a reference to an object of the
- >class ( I don't think that this is intended ).
-
- I don't think it matters. The conversion is the identity conversion. In
- places where conversions are required, there is almost always more than
- one way to achieve the conversion. (Often there is an infinite number
- of possible conversion sequences, such as short->int->short->int->short->...->int.)
- The explicit rule in such cases is to choose the shortest possible sequence
- of conversions.
-
- Suppose a copy constructor T::T(const T&) is viewed as a conversion from T to
- T. If such a conversion is "needed", the shortest conversion sequence must be
- chosen. That would be the null sequence, and so the copy ctor would never
- be used or even considered for that purpose. (Just as the sequence
- int->Rational->float would never be considered in converting an int to
- a float.)
-
- ---
- Steve Clamage, stephen.clamage@eng.sun.com
-
-
-
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-